import { createRouter, createWebHashHistory } from 'vue-router'
import store from "../store/index"

const home = () => import("../views/home/Home")
const Log = () => import("../views/login/Log");
const sign = () => import("../views/login/Sign")
const detailFrameWork = () => import("../components/content/detailPage/DetailFrameWork")
const shoppingcar = () => import("../views/shoppingcar/ShoppingCar")
const personEnter = () => import("../views/personenter/PersonEnter")
const submitOrder = () => import("../views/submitorder/SubmitOrder")
const payment = () => import("../views/payment/Payment")
const paymentChildSuccess = () => import("../views/payment/PaymentChildSeccess")

const routes = [
  {path: "",redirect: "/home"},
  {path: "/home",component: home},
  {path: "/log", component: Log},
  {path: "/sign", component: sign},
  {path: "/detail", component: detailFrameWork},
  {path: "/shoppingcar", component: shoppingcar},
  {path: "/personEnter", component: personEnter},
  {path: "/submitOrder", component: submitOrder},
  {path: "/payment", component: payment},
  {path: "/paymentChildSuccess",component: paymentChildSuccess}
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to,from,next) => {
  if (to.path == "/shoppingcar" || to.path == "/personEnter") {//在进入购物车或者个人中心之前要先判断用户是否登陆
    if (!store.state.UserMsg.UserMsg.logStatus){
      next({path: "/log"})
    }
  }
  next();
})

export default router
